/**正则表达式*/ 
import http from '../apis/api.js';
let reg = {
  id: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
  phone: /^1(3|4|5|6|7|8|9)\d{9}$/ /**手机号码验证 */
}
/**获取角色列表 */
function getRole(){
  return new Promise((resole,reject)=>{
    http.getRole().then(res=>{
      let roleList = []
      res.content.forEach(el => {
        roleList.push(el.name)
      })
      resole(roleList)
    },error=>{
      reject(error);
    })
  })
}
/**查询个人信息 */
function getUserInfo(){
  return new Promise((resole, reject) => {
    http.getUserinfo().then(res => {
      resole(res)
    }, error => {
      reject(error);
    })
  })
}
function timeList(){
  const date = new Date()
  let timeArray={
    years:[],
    months:[],
    days:[],
    hours:[],
    minutes:[],
    seconds:[]
  }
  for (let i = date.getFullYear() - 2; i <= date.getFullYear() + 2; i++) {
    years.push(i)
  }

  for (let i = 1; i <= 12; i++) {
    months.push(i<10?'0'+i:i)
  }

  for (let i = 1; i <= 31; i++) {
    days.push(i < 10 ? '0' + i : i)
  }
  for (let i = 1; i <= 24; i++) {
    hours.push(i < 10 ? '0' + i : i)
  }

  for (let i = 0; i <= 60; i++) {
    minutes.push(i < 10 ? '0' + i : i);
    seconds.push(i < 10 ? '0' + i : i)
  };
  return timeArray;
}
module.exports = {
  reg,
  getRole,
  getUserInfo,
  timeList
}
